package modelLayer;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;

public class Flavour {
	private static int idIterator;
	private int id;
	private String flavour;
	private int bottles;
	private ArrayList<Sale> sales;
	private boolean limited;
	
	public Flavour(String flavour){
		idIterator++;
		this.id = idIterator;
		this.flavour = flavour;
		this.bottles = 0;
		sales = new ArrayList<Sale>();
		limited = false;
	}
	
	public Flavour(int id, String flavour, int bottles, int limited){
		idIterator++;
		this.id = id;
		this.flavour = flavour;
		this.bottles = bottles;
		this.sales = new ArrayList<Sale>();
		if(limited == 0){
			this.limited = false;
		}else{
			this.limited = true;
		}
	}

	public String getFlavour() {
		return flavour;
	}

	public void setFlavour(String flavour) {
		this.flavour = flavour;
	}

	public int getBottles() {
		return bottles;
	}

	public void setBottles(int bottles) {
		this.bottles = bottles;
	}

	public void addSales(int amount) {
		Date date = new Date();
		Calendar cal = Calendar.getInstance();
		cal.setTime(date);
		int week = cal.get(Calendar.WEEK_OF_YEAR);
		boolean exist = false;
		for(Sale s : sales){
			
			cal.setTime(s.getRealDate());
			int weeks = cal.get(Calendar.WEEK_OF_YEAR);
			if(week == weeks){
				s.addToAmount(amount);
				exist = true;
				break;
			}
		}
		if(!exist){
			sales.add(new Sale(amount));
		}
	}
	
	public void addSales(int id, int amount, Date date) {
		sales.add(new Sale(id, amount, date));
	}

	public int getId() {
		return id;
	}
	
	public ArrayList<Sale> getSales(){
		return sales;
	}
	
	public int hasSales(){
		if(sales.size() == 0){
			return 0;
		}else{
			return 1;
		}
	}
	
	public boolean isLimited(){
		return limited;
	}
	
	public void toggleLimited(){
		limited = !limited;
	}
}
